package com.baic.ibase.controller.api.v1;


import com.alibaba.fastjson2.JSON;
import com.baic.ibase.models.dao.DeviceMessageLog;
import com.baic.ibase.models.dao.Devices;
import com.baic.ibase.models.req.common.ApiResponse;
import com.baic.ibase.models.req.common.IdRequest;
import com.baic.ibase.models.req.common.PageRequest;
import com.baic.ibase.models.req.devices.CreateDeviceReq;
import com.baic.ibase.models.req.devices.DeleteDeviceReq;
import com.baic.ibase.models.req.devices.DeviceMessageLogPageReq;
import com.baic.ibase.models.req.devices.ExecuteCommandReq;
import com.baic.ibase.service.devices.DeviceMessageLogService;
import com.baic.ibase.service.devices.DeviceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/api/v1/devices")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private DeviceMessageLogService deviceMessageLogService;


    /**
     * @api {POST} /api/v1/devices/ListDevices 查询设备列表
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName ListDevices()
     * @apiParam (请求体) {Number} pageNum
     * @apiParam (请求体) {Number} pageSize
     * @apiParam (请求体) {String} sort
     * @apiParam (请求体) {String} order
     * @apiParam (请求体) {String} requestId
     * @apiParamExample 请求体示例
     * {"requestId":"WQouOeD6","pageSize":9808,"sort":"ETFvGkHf","pageNum":345,"order":"xOCeod"}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {Array} data.records
     * @apiSuccess (响应结果) {Number} data.records.deviceId
     * @apiSuccess (响应结果) {String} data.records.deviceName 设备名称
     * @apiSuccess (响应结果) {String} data.records.deviceClientId clientId
     * @apiSuccess (响应结果) {String} data.records.deviceOs 操作系统
     * @apiSuccess (响应结果) {String} data.records.deviceOsVersion 操作系统版本
     * @apiSuccess (响应结果) {String} data.records.deviceClientType 客户端类型
     * @apiSuccess (响应结果) {String} data.records.deviceClientVersion 客户端版本
     * @apiSuccess (响应结果) {Number} data.records.deviceStatus 状态
     * @apiSuccess (响应结果) {Number} data.records.deviceConnectionStatus 连接状态
     * @apiSuccess (响应结果) {Object} data.records.lastConnectTime 最后登录时间
     * @apiSuccess (响应结果) {String} data.records.deviceIp 终端ip地址
     * @apiSuccess (响应结果) {String} data.records.deviceMac 终端mac地址
     * @apiSuccess (响应结果) {String} data.records.deviceVin 车辆vin码
     * @apiSuccess (响应结果) {Number} data.records.productId 产品id
     * @apiSuccess (响应结果) {Number} data.records.userId 所属用户id
     * @apiSuccess (响应结果) {Number} data.records.projectId 归属项目id
     * @apiSuccess (响应结果) {Number} data.records.departmentId 归属部门ID
     * @apiSuccess (响应结果) {Object} data.records.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.records.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.records.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.records.updatedUserId 更新人
     * @apiSuccess (响应结果) {Number} data.total
     * @apiSuccess (响应结果) {Number} data.size
     * @apiSuccess (响应结果) {Number} data.current
     * @apiSuccess (响应结果) {Array} data.orders
     * @apiSuccess (响应结果) {String} data.orders.column
     * @apiSuccess (响应结果) {Boolean} data.orders.asc
     * @apiSuccessExample 响应结果示例
     * {"traceId":"ebbde","code":5537,"data":{"total":8836,"current":755,"size":3510,"records":[{"deviceIp":"aBnpiKaBf","deviceClientType":"o5mw","createdUserId":4771,"productId":8217,"deviceVin":"WW","deviceOs":"amlwBvO","departmentId":6597,"deviceConnectionStatus":9502,"deviceOsVersion":"rx","deviceId":5813,"deviceName":"IXydVRi","userId":2599,"deviceClientVersion":"c","deviceStatus":7656,"deviceClientId":"MtNpnU","deviceMac":"qM8","projectId":8772,"updatedUserId":8059}],"orders":[{"asc":true,"column":"nMErps0yf"}]},"success":false,"message":"cLR","errors":"albuJOF7P"}
     */
    @PostMapping("/ListDevices")
    public ApiResponse<Page<Devices>> ListDevices(@RequestBody PageRequest req)
    {
        log.info("ListDevices pageNum:{},pageSize:{}", req.getPageNum(), req.getPageSize());
        Page<Devices> page = deviceService.page(new Page<>(req.getPageNum(), req.getPageSize()));
        log.info("ListDevices page:{}, resp: {}", req, page);
        return ApiResponse.ok(page);
    }

    /**
     * @api {POST} /api/v1/devices/AddDevice 添加设备
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName AddDevices()
     * @apiParam (请求体) {String} requestId
     * @apiParam (请求体) {String} deviceName
     * @apiParam (请求体) {String} deviceVin
     * @apiParam (请求体) {String} deviceOs
     * @apiParam (请求体) {String} deviceOsVersion
     * @apiParam (请求体) {Number} productId
     * @apiParam (请求体) {String} deviceClientType
     * @apiParam (请求体) {String} deviceClientVersion
     * @apiParam (请求体) {String} description
     * @apiParamExample 请求体示例
     * {"deviceClientType":"bG2Ofi1P","productId":747,"deviceVin":"o","requestId":"oUPw","deviceOs":"S3EvqKLA","description":"x","deviceOsVersion":"MZ","deviceName":"h6f","deviceClientVersion":"JG24eL4co"}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {Number} data.deviceId
     * @apiSuccess (响应结果) {String} data.deviceName 设备名称
     * @apiSuccess (响应结果) {String} data.deviceClientId clientId
     * @apiSuccess (响应结果) {String} data.deviceOs 操作系统
     * @apiSuccess (响应结果) {String} data.deviceOsVersion 操作系统版本
     * @apiSuccess (响应结果) {String} data.deviceClientType 客户端类型
     * @apiSuccess (响应结果) {String} data.deviceClientVersion 客户端版本
     * @apiSuccess (响应结果) {Number} data.deviceStatus 状态
     * @apiSuccess (响应结果) {Number} data.deviceConnectionStatus 连接状态
     * @apiSuccess (响应结果) {Object} data.lastConnectTime 最后登录时间
     * @apiSuccess (响应结果) {String} data.deviceIp 终端ip地址
     * @apiSuccess (响应结果) {String} data.deviceMac 终端mac地址
     * @apiSuccess (响应结果) {String} data.deviceVin 车辆vin码
     * @apiSuccess (响应结果) {Number} data.productId 产品id
     * @apiSuccess (响应结果) {Number} data.userId 所属用户id
     * @apiSuccess (响应结果) {Number} data.projectId 归属项目id
     * @apiSuccess (响应结果) {Number} data.departmentId 归属部门ID
     * @apiSuccess (响应结果) {Object} data.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.updatedUserId 更新人
     * @apiSuccessExample 响应结果示例
     * {"traceId":"CnhVjl","code":938,"data":{"deviceIp":"eMqRSTeUzp","deviceClientType":"H","createdUserId":2884,"productId":3483,"deviceVin":"JRN","deviceOs":"SdmTeS","departmentId":146,"deviceConnectionStatus":4306,"deviceOsVersion":"sd0Tu8e8B","deviceId":4252,"deviceName":"Yf","userId":12,"deviceClientVersion":"C1cO","deviceStatus":9114,"deviceClientId":"HOvl","deviceMac":"6u9ZN","projectId":440,"updatedUserId":6704},"success":false,"message":"QzK5","errors":"rocB5uDuu"}
     */
    @PostMapping("/AddDevice")
    public ApiResponse<Devices> AddDevices(@RequestBody CreateDeviceReq req)
    {
        log.info("AddDevices req:{}", req);
        Devices devices = new Devices();
        devices.setDeviceName(req.getDeviceName());
        devices.setDeviceVin(req.getDeviceVin());
        devices.setDeviceOs(req.getDeviceOs());
        devices.setDeviceOsVersion(req.getDeviceOsVersion());
        devices.setDeviceClientType(req.getDeviceClientType());
        devices.setDeviceClientVersion(req.getDeviceClientVersion());
        devices.setProductId(req.getProductId());
        devices.setUserId(1L);
        devices.setProjectId(1L);
        devices.setDepartmentId(1L);
        devices.setUpdatedUserId(1L);
        devices.setCreatedUserId(1L);
        boolean result = deviceService.save(devices);
        if (result) {
            return ApiResponse.ok(devices);
        } else {
            return ApiResponse.error(500, "添加设备失败");
        }
    }

    /**
     * @api {POST} /api/v1/devices/DeleteDevice 删除设备
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName DeleteDevices()
     * @apiParam (请求体) {Number} id
     * @apiParam (请求体) {String} requestId
     * @apiParamExample 请求体示例
     * {"requestId":"Ws067qnftd","id":3968}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Boolean} data
     * @apiSuccessExample 响应结果示例
     * {"traceId":"xddCQtGkRr","code":5263,"data":false,"success":true,"message":"Y417eEf","errors":"CbR1z"}
     */
    @PostMapping("/DeleteDevice")
    public ApiResponse<Boolean> DeleteDevices(@RequestBody @Validated DeleteDeviceReq req)
    {

        if (deviceService.removeById(req.getId())) {
            return ApiResponse.ok(true);
        } else {
            return ApiResponse.error(500, "删除设备失败");
        }

    }

    /**
     * @api {POST} /api/v1/devices/GetDevice 查询设备详情
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName GetDevices()
     * @apiParam (请求体) {Number} id
     * @apiParam (请求体) {String} requestId
     * @apiParamExample 请求体示例
     * {"requestId":"7","id":4223}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {Number} data.deviceId
     * @apiSuccess (响应结果) {String} data.deviceName 设备名称
     * @apiSuccess (响应结果) {String} data.deviceClientId clientId
     * @apiSuccess (响应结果) {String} data.deviceOs 操作系统
     * @apiSuccess (响应结果) {String} data.deviceOsVersion 操作系统版本
     * @apiSuccess (响应结果) {String} data.deviceClientType 客户端类型
     * @apiSuccess (响应结果) {String} data.deviceClientVersion 客户端版本
     * @apiSuccess (响应结果) {Number} data.deviceStatus 状态
     * @apiSuccess (响应结果) {Number} data.deviceConnectionStatus 连接状态
     * @apiSuccess (响应结果) {Object} data.lastConnectTime 最后登录时间
     * @apiSuccess (响应结果) {String} data.deviceIp 终端ip地址
     * @apiSuccess (响应结果) {String} data.deviceMac 终端mac地址
     * @apiSuccess (响应结果) {String} data.deviceVin 车辆vin码
     * @apiSuccess (响应结果) {Number} data.productId 产品id
     * @apiSuccess (响应结果) {Number} data.userId 所属用户id
     * @apiSuccess (响应结果) {Number} data.projectId 归属项目id
     * @apiSuccess (响应结果) {Number} data.departmentId 归属部门ID
     * @apiSuccess (响应结果) {Object} data.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.updatedUserId 更新人
     * @apiSuccessExample 响应结果示例
     * {"traceId":"D4","code":36,"data":{"deviceIp":"GPsW4UdJ","deviceClientType":"27","createdUserId":1854,"productId":247,"deviceVin":"XURXZ2cri","deviceOs":"IDcil8","departmentId":4275,"deviceConnectionStatus":1857,"deviceOsVersion":"6RJVVS4Hy","deviceId":908,"deviceName":"1ga2","userId":4073,"deviceClientVersion":"6N","deviceStatus":7306,"deviceClientId":"tiG","deviceMac":"GWAia01","projectId":6512,"updatedUserId":7638},"success":true,"message":"jFQv0il3b","errors":"hjX"}
     */
    @PostMapping("/GetDevice")
    public ApiResponse<Devices> GetDevices(@RequestBody IdRequest req)
    {
        log.info("GetDevices req:{}", req);
        Devices devices = deviceService.getById(req.getId());
        return ApiResponse.ok(devices);
    }

    /**
     * @api {POST} /api/v1/devices/UpdateDevice 更新设备信息
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName UpdateDevices()
     * @apiParam (请求体) {Number} deviceId
     * @apiParam (请求体) {String} deviceName 设备名称
     * @apiParam (请求体) {String} deviceClientId clientId
     * @apiParam (请求体) {String} deviceOs 操作系统
     * @apiParam (请求体) {String} deviceOsVersion 操作系统版本
     * @apiParam (请求体) {String} deviceClientType 客户端类型
     * @apiParam (请求体) {String} deviceClientVersion 客户端版本
     * @apiParam (请求体) {Number} deviceStatus 状态
     * @apiParam (请求体) {Number} deviceConnectionStatus 连接状态
     * @apiParam (请求体) {Object} lastConnectTime 最后登录时间
     * @apiParam (请求体) {String} deviceIp 终端ip地址
     * @apiParam (请求体) {String} deviceMac 终端mac地址
     * @apiParam (请求体) {String} deviceVin 车辆vin码
     * @apiParam (请求体) {Number} productId 产品id
     * @apiParam (请求体) {Number} userId 所属用户id
     * @apiParam (请求体) {Number} projectId 归属项目id
     * @apiParam (请求体) {Number} departmentId 归属部门ID
     * @apiParam (请求体) {Object} createdTime 创建时间
     * @apiParam (请求体) {Object} updatedTime 更新时间
     * @apiParam (请求体) {Number} createdUserId 创建人
     * @apiParam (请求体) {Number} updatedUserId 更新人
     * @apiParamExample 请求体示例
     * {"deviceIp":"h1gxj13Z","deviceClientType":"qq4O1py","createdUserId":7124,"productId":9205,"deviceVin":"xH","deviceOs":"pTAnNKweq","departmentId":8486,"deviceConnectionStatus":8359,"deviceOsVersion":"EE","deviceId":4960,"deviceName":"w","userId":8269,"deviceClientVersion":"exG5f2","deviceStatus":1693,"deviceClientId":"Qo","deviceMac":"S","projectId":7017,"updatedUserId":5700}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {Number} data.deviceId
     * @apiSuccess (响应结果) {String} data.deviceName 设备名称
     * @apiSuccess (响应结果) {String} data.deviceClientId clientId
     * @apiSuccess (响应结果) {String} data.deviceOs 操作系统
     * @apiSuccess (响应结果) {String} data.deviceOsVersion 操作系统版本
     * @apiSuccess (响应结果) {String} data.deviceClientType 客户端类型
     * @apiSuccess (响应结果) {String} data.deviceClientVersion 客户端版本
     * @apiSuccess (响应结果) {Number} data.deviceStatus 状态
     * @apiSuccess (响应结果) {Number} data.deviceConnectionStatus 连接状态
     * @apiSuccess (响应结果) {Object} data.lastConnectTime 最后登录时间
     * @apiSuccess (响应结果) {String} data.deviceIp 终端ip地址
     * @apiSuccess (响应结果) {String} data.deviceMac 终端mac地址
     * @apiSuccess (响应结果) {String} data.deviceVin 车辆vin码
     * @apiSuccess (响应结果) {Number} data.productId 产品id
     * @apiSuccess (响应结果) {Number} data.userId 所属用户id
     * @apiSuccess (响应结果) {Number} data.projectId 归属项目id
     * @apiSuccess (响应结果) {Number} data.departmentId 归属部门ID
     * @apiSuccess (响应结果) {Object} data.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.updatedUserId 更新人
     * @apiSuccessExample 响应结果示例
     * {"traceId":"1jpolyz","code":1731,"data":{"deviceIp":"Mtg3ur","deviceClientType":"23HSFl8","createdUserId":6812,"productId":26,"deviceVin":"eE1SMfim","deviceOs":"n9Fek","departmentId":3822,"deviceConnectionStatus":3186,"deviceOsVersion":"4LAs","deviceId":3507,"deviceName":"fi","userId":4203,"deviceClientVersion":"k","deviceStatus":7153,"deviceClientId":"zpBBa","deviceMac":"EdIdH9D","projectId":176,"updatedUserId":6633},"success":false,"message":"TJ1gyqfdf","errors":"VUz"}
     */
    @PostMapping("/UpdateDevice")
    public ApiResponse<Devices> UpdateDevices(@RequestBody Devices req)
    {
        log.info("UpdateDevices req:{}", req);
        boolean result = deviceService.updateById(req);
        if (result) {
            return ApiResponse.ok(req);
        } else {
            return ApiResponse.error(500, "更新设备失败");
        }
    }


    /**
     * @api {POST} /api/v1/devices/executeCommand 发送给设备指令
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName executeCommand()
     * @apiParam (请求体) {String} deviceId 设备ID
     * @apiParam (请求体) {String} command 发送指令，枚举类型
     * @apiParam (请求体) {Object} commandParam 指令参数
     * @apiParam (请求体) {Number} userId
     * @apiParam (请求体) {String} requestId
     * @apiParamExample 请求体示例
     * {"requestId":"s9","commandParam":{},"deviceId":"U8TEjgEF","userId":350,"command":"START_CAN_CAPTURE"}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Boolean} data
     * @apiSuccessExample 响应结果示例
     * {"traceId":"g4QkN","code":7259,"data":false,"success":true,"message":"u6pMoZ","errors":"5Uk8lM82"}
     */
    @PostMapping("/executeCommand")
    public ApiResponse<Boolean> executeCommand(@RequestBody @Validated ExecuteCommandReq req, @RequestAttribute Long userId) {
        log.info("executeCommand req:{}", req);

        req.setUserId(userId);
        return ApiResponse.ok(deviceService.executeCommand(req));
    }


    /**
     * @api {POST} /api/v1/devices/message/ListMessageLog 消息日志列表
     * @apiVersion 1.0.0
     * @apiGroup DeviceController
     * @apiName messageLogs()
     * @apiParam (请求体) {Number} deviceId 设备ID
     * @apiParam (请求体) {Number} pageNum
     * @apiParam (请求体) {Number} pageSize
     * @apiParam (请求体) {String} sort
     * @apiParam (请求体) {String} order
     * @apiParam (请求体) {String} requestId
     * @apiParamExample 请求体示例
     * {"requestId":"nJOINQJgBS","pageSize":9799,"sort":"QTzUSWd","deviceId":1874,"pageNum":7852,"order":"FV0Qh3G"}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {Array} data.records
     * @apiSuccess (响应结果) {Number} data.records.id
     * @apiSuccess (响应结果) {Number} data.records.deviceId 设备ID
     * @apiSuccess (响应结果) {String} data.records.requestId 请求ID
     * @apiSuccess (响应结果) {String} data.records.deviceName 设备名称
     * @apiSuccess (响应结果) {String} data.records.deviceClientId client_id
     * @apiSuccess (响应结果) {String} data.records.deviceCommand 命令
     * @apiSuccess (响应结果) {Object} data.records.deviceCommandParam 命令参数
     * @apiSuccess (响应结果) {Object} data.records.deviceCommandResponse 响应结果
     * @apiSuccess (响应结果) {Number} data.records.userId 用户ID
     * @apiSuccess (响应结果) {String} data.records.status 命令执行结果
     * @apiSuccess (响应结果) {Object} data.records.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.records.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.records.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.records.updatedUserId 更新人
     * @apiSuccess (响应结果) {Number} data.total
     * @apiSuccess (响应结果) {Number} data.size
     * @apiSuccess (响应结果) {Number} data.current
     * @apiSuccess (响应结果) {Array} data.orders
     * @apiSuccess (响应结果) {String} data.orders.column
     * @apiSuccess (响应结果) {Boolean} data.orders.asc
     * @apiSuccess (响应结果) {Boolean} data.optimizeCountSql
     * @apiSuccess (响应结果) {Boolean} data.searchCount
     * @apiSuccess (响应结果) {Boolean} data.optimizeJoinOfCountSql
     * @apiSuccess (响应结果) {Number} data.maxLimit
     * @apiSuccess (响应结果) {String} data.countId
     * @apiSuccessExample 响应结果示例
     * {"traceId":"dbkl0Qfj","code":7674,"data":{"total":2587,"current":4093,"size":5961,"optimizeCountSql":false,"records":[{"deviceCommandParam":{},"createdUserId":8716,"deviceCommandResponse":{},"deviceId":6064,"deviceName":"aTBlN9","userId":7885,"deviceCommand":"START_OBD_CAPTURE","requestId":"bLK","deviceClientId":"NPQ","id":1470,"updatedUserId":7273,"status":"xsxd3"}],"maxLimit":7943,"searchCount":false,"optimizeJoinOfCountSql":true,"orders":[{"asc":true,"column":"4vYAFtGCM"}],"countId":"wrp8NCWY"},"success":true,"message":"SAyBZ","errors":"C"}
     */
    @PostMapping("/message/ListMessageLog")
    public ApiResponse<Page<DeviceMessageLog>> messageLogs(@RequestBody @Validated DeviceMessageLogPageReq req) {
        LambdaQueryWrapper<DeviceMessageLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DeviceMessageLog::getDeviceId, req.getDeviceId());

        Page<DeviceMessageLog> page = new Page<>(req.getPageNum(), req.getPageSize());
        Page<DeviceMessageLog> pageRes = deviceMessageLogService.page(page, queryWrapper);
        return ApiResponse.ok(pageRes);
    }

}
